import static org.junit.Assert.*;

import org.junit.Test;

public class read_write_race_test {
  @Test
  public void test() {
    read_write_race account = new read_write_race();

    // Create two threads, one for deposit, one for writhdraw.
    Thread t1 = new Thread(() -> {
      for (int i = 0; i < 1000; i++) {
        account.deposit(1);
      }
    });

    Thread t2 = new Thread(() -> {
      for (int i = 0; i < 1000; i++) {
        account.withdraw(1);
      }
    });

    t1.start();
    t2.start();

    try {
      t1.join();
      t2.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    assertEquals(0, account.getBalance());
  }
}
